var verify_dataPermission_baseMsg = JSON.parse('{"CODE":0, "ACTION":"","LEVEL":"T1", "MSG":"","DATA":"","SCRIPTNAME":"verify_dataPermission"}');
var verify_dataPermission_flag = false;
if (max_role != 'AR001023-qa') {
    if (!isNull(category_user_result_list)) {
        var luyanCategory = 98;
        var luyanUserList = [];
        var pcs_buyerId = !isNull(buyer_id) ? buyer_id.toUpperCase() : '';
        var pcs_updateBy = !isNull(update_by) ? update_by.toUpperCase() : '';
        category_user_result_list.forEach(function (category_user_result) {
            if (!isNull(category_user_result.luYanMaId)) {
                luyanUserList.push(category_user_result.luYanMaId.toUpperCase());
            }
            if (!isNull(category_user_result.luYanBuyerId)) {
                luyanUserList.push(category_user_result.luYanBuyerId.toUpperCase());
            }
            if (!isNull(category_user_result.luYanDmmId)) {
                luyanUserList.push(category_user_result.luYanDmmId.toUpperCase());
            }
            if (!isNull(category_user_result.luYanGmmId)) {
                luyanUserList.push(category_user_result.luYanGmmId.toUpperCase());
            }
        });
        category_user_result_list.forEach(function (category_user_result) {
            if (category_user_result.category == category_nbr) {
                var maId = !isNull(category_user_result.maId) ? category_user_result.maId.toUpperCase() : category_user_result.maId;
                var ma2Id = !isNull(category_user_result.ma2Id) ? category_user_result.ma2Id.toUpperCase() : category_user_result.ma2Id;
                var buyerId = !isNull(category_user_result.buyerId) ? category_user_result.buyerId.toUpperCase() : category_user_result.buyerId;
                var muBuyerId = !isNull(category_user_result.muBuyerId) ? category_user_result.muBuyerId.toUpperCase() : category_user_result.muBuyerId;
                var dmmId = !isNull(category_user_result.dmmId) ? category_user_result.dmmId.toUpperCase() : category_user_result.dmmId;
                var gmmId = !isNull(category_user_result.gmmId) ? category_user_result.gmmId.toUpperCase() : category_user_result.gmmId;
                var cmoId = !isNull(category_user_result.cmoId) ? category_user_result.cmoId.toUpperCase() : category_user_result.cmoId;

                if (!verify_dataPermission_flag && sub_category_nbr == luyanCategory
                    && (luyanUserList.indexOf(pcs_updateBy) != -1 || luyanUserList.indexOf(pcs_updateBy) != -1)) {
                    verify_dataPermission_flag = true;
                }

                if (!verify_dataPermission_flag
                    && ((maId == pcs_buyerId || ma2Id == pcs_buyerId || buyerId == pcs_buyerId || muBuyerId == pcs_buyerId
                            || dmmId == pcs_buyerId || gmmId == pcs_buyerId || cmoId == pcs_buyerId)
                        && (maId == pcs_updateBy || ma2Id == pcs_updateBy || buyerId == pcs_updateBy || muBuyerId == pcs_updateBy
                            || dmmId == pcs_updateBy || gmmId == pcs_updateBy || cmoId == pcs_updateBy))) {
                    verify_dataPermission_flag = true;
                }
            }
        })
    }
} else {
    verify_dataPermission_flag = true;
}

if (!verify_dataPermission_flag) {
    verify_dataPermission_baseMsg.CODE = 2;
    verify_dataPermission_baseMsg.ACTION = 'error';
    verify_dataPermission_baseMsg.MSG = '权限原因，无法维护';
}

JSON.stringify(verify_dataPermission_baseMsg);
